/*
 * Lenovo Group
 * Copyright (c) 2015-2016 All Rights Reserved.
 * Project Name: lmrp-android app
 * Create Time: 16-2-16 下午6:48
 */

package com.lenovo.mso2o.view;

import android.content.Context;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.View;

import com.lenovo.framework.util.DLog;

/**
 * Created by lenovo on 2015/12/22.
 */
public class RecycleLayoutManager extends GridLayoutManager {
    public int getmLines() {
        return mLines;
    }

    public void setmLines(int mLines) {
        this.mLines = mLines;
    }

    public int mLines;

    public RecycleLayoutManager(Context context, int spanCount, int orientation, boolean reverseLayout) {
        super(context, spanCount, orientation, reverseLayout);
    }

    public RecycleLayoutManager(Context context, int spanCount, int mLines) {
        super(context, spanCount);
        this.mLines = mLines;
    }

    public RecycleLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    @Override
    public void onMeasure(RecyclerView.Recycler recycler, RecyclerView.State state, int widthSpec, int heightSpec) {
        try {
            View view = recycler.getViewForPosition(0);
            if (view != null) {
                measureChild(view, widthSpec, heightSpec);
                int measuredWidth = View.MeasureSpec.getSize(widthSpec);

                int measuredHeight = view.getMeasuredHeight();
                measuredHeight = 2 * mLines* measuredHeight;
                setMeasuredDimension(measuredWidth, measuredHeight);
            }
        }catch (Exception e){
            DLog.e("ERROR",e.toString());
            setMeasuredDimension(0,0);
        }

    }
}